package com.itheima.test;

import java.util.ArrayList;

public class ArrayListDemo05 {
    public static void main(String[] args) {
        // 1.定义集合
        ArrayList<Phone> list = new ArrayList<>();

        // 2.添加手机信息
        Phone p1 = new Phone("小米", 1000);
        Phone p2 = new Phone("苹果", 8000);
        Phone p3 = new Phone("华为", 2000);

        list.add(p1);
        list.add(p2);
        list.add(p3);


        ArrayList<Phone> newList = getPriceRange(list,3000);
        for (int i = 0; i < newList.size(); i++) {
            Phone phone = newList.get(i);
            System.out.println(phone.getBrand() + ", " + phone.getPrice());
        }
    }

    //定义获取低于多少价格的数据
    public static ArrayList<Phone> getPriceRange(ArrayList<Phone> list, int price) {
        ArrayList<Phone> arr = new ArrayList<>();
        for (Phone ph : list) {
            if (ph.getPrice() < price) {
                arr.add(ph);
            }
        }

        return arr;
    }

}
